<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
    <head>
        <title>用户管理</title>
        <meta http-equiv="content-type" content="text/html;charset=utf-8">
        <link href="../../css/mine.css" type="text/css" rel="stylesheet">
        <script src="/js/jquery.js"></script>
    </head>

    <body>

        <div class="div_head">
            <span>
                <span style="float:left">当前位置是：-》资源管理》用户管理</span>
                <span style="float:right;margin-right: 8px;font-weight: bold">
                    <a style="text-decoration: none" href="">【返回】</a>
                </span>
            </span>
        </div>
        <div></div>

        <div style="font-size: 13px;margin: 10px 5px">
            <form id="form" action="/user/add" method="post" >
            <table border="1" width="100%" class="table_a">
                <tr>
                    <td width="120px;">用户编号<span style="color:red">*</span>：</td>
                    <td>
                        <input type="text" id="userid" name="userid" value="201501010" />
                        <span style="color: red"></span>
                    </td>
                </tr>
                <tr>
                    <td>登录账号<span style="color:red">*</span>：</td>
                    <td>
                       <input type="text" name="account" value="zhangsan" />
                    </td>
                </tr>
               
                <tr>
                    <td>用户姓名<span style="color:red">*</span>：</td>
                    <td>
						<input type="text" name="username" value="张三" /></td>
                </tr>
                <tr>
                    <td>密码<span style="color:red">*</span>：</td>
                    <td>
						<input type="text"  name="password" value="......" />
					</td>
                </tr>

                <tr>
                    <td>所属部门<span style="color:red">*</span>：</td>
                    <td>

                        <select id="dept" name="userappartment">
                            <option value="-1">---请选择---</option>
                            <c:forEach items="${deptList}" var="dept">
                                <option value="${dept.id}">${dept.appartmentfullname}</option>
                            </c:forEach>
                        </select>
                    </td>
                </tr>


                <tr>
                    <td>所属职位<span style="color:red">*</span>：</td>
                    <td>
                        
						<select id="role" name="userrole">
                            <option value="-1">---请选择---</option>

                        </select>
                    </td>
                </tr>



				<tr>
                    <td>身份证<span style="color:red">*</span>：</td>
                    <td>
                        <input type="text" name="idcard" value="372902198708084567" />
                    </td>
                </tr>

				<tr>
                    <td>联系电话<span style="color:red">*</span>：</td>
                    <td>
                        <input type="text" name="phonenumber" value="17718181920"/>
                    </td>                
                </tr>

				<tr>
                    <td>邮箱<span style="color:red">*</span>：</td>
                    <td>
                        <input type="text" name="email" value="AAA@163.com" />
                    </td>                
                </tr>

				<tr>
                    <td>联系地址：</td>
                    <td>
                        <input type="text" name="address" value="海淀区软件园孵化器" />
                    </td>                
                </tr>
                <tr>
                    <td colspan="2" align="center">
                        <input id="addBtn" type="button" onclick="add()"  value="添加">
						<input type="r.0eset" value="清空">
                    </td>
                </tr>  
            </table>
            </form>
        </div>
        <script>
            // 部门、职位二级联动
            $("#dept").change(function () {
                //1.获得被选中的value值
                var deptId= $(this).val();
                if(deptId==-1){
                    alert("请选择部门");
                }else{
                    //将deptId的值传给服务器，服务器进行查询
                    $.ajax({
                        url:"/user/getRoles",
                        data:"deptId="+deptId,
                        type:"post",
                        dataType:"json",
                        success:function(rs){//rs用来接受返回的结果
                            $("#role")[0].length=0;//让下拉框的长度为0
                            for(var i=0;i<rs.length;i++){
                                $("#role")[0].add(new Option(rs[i].permname,rs[i].id));//Option(显示到标签对中的值,value值)
                            }
                        }
                    })
                }

            });

            //添加
            function add() {
                //获取用户编号
                var userid=$("#userid").val();
                alert(userid)
                //发送AJAX，异步校验用户编号是否重复
                $.getJSON(
                    "/user/check-userid?userid="+userid,
                    null,
                    function (result) {
                        if (result.code==0) {
                            // //启用按钮
                            // $("#addBtn").attr('disabled',false);
                            //用户编号可用，直接提交表单
                            $("#form").submit();
                        }
                        else {
                            //用户编号不可用或者为空,给出提示
                            alert(result.msg);
                            //禁用提交按钮
                            // $("#addBtn").attr('disabled',true);
                        }

                    }
                );
            }

        </script>
    </body>
</html>